<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentGroupDetails.class.php, $Author:  $ */

/** Component for display group details
 * @version $Id: PhpFox_ComponentGroupDetails.class.php
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentGroupDetails extends BaseComponent
{
    /** Processing method
     */

    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('read_only', 'full'));

        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */

        $oAccountService = &App::getModuleService('Account', 'Account');

        $oReq = &App::getRequest();
        /* @var $oReq Request */

        $oTpl = $this->_oModule->getTemplate();

        $oUser = $this->getParam('user');
        $iGroupId = $oReq->getInt('id', 0);

        $bIsMember = (App::getUser('user') ? $oGroupsService->isMember($iGroupId, App::getUser('user')) : false);
        $aGroupData = $oGroupsService->getGroupData($iGroupId);

        if(!$aGroupData)
            App::gotoUrl('public.groups');
        /* Check permissions */
        $aInviteData = $oGroupsService->getInviteData($iGroupId, App::getUser('user'));

        if(!($bIsMember OR App::isStaff()) && $aGroupData['hide_group'] == 'Yes' )
        {
        	if ( !App::getUser('user') )
        	{
				App::gotoUrl('public.groups.private', array('id' => $iGroupId));
        	}
            if(!isset($aInviteData['id']))
            {
                App::gotoUrl('public.groups.private', array('id' => $iGroupId));
			}
		}


        if($aGroupData['user'] == App::getUser('user'))
            $isOwner = true;
        else
            $isOwner = false;

	    (App::getUser('type')==0? $bIsAdmin = true : $bIsAdmin = false);

        $oUserOwner = $oAccountService->getByUsername($aGroupData['user']);
        $oUserOwner->aData['user_online'] = $oAccountService->isOnline($oUserOwner->aData['user']);

        $oGroupsService->addGroupView($iGroupId);

        $oTpl->assignSrc(array(
            'aUser'             => $oUserOwner->aData,
            'isAdmin'           => App::isStaff(),
            'isOwner'           => $isOwner,
            'isMember'          => $bIsMember,
            'aGroupData'        => $aGroupData,
            'sImageUrl'         => App::getParam('user.pic.url'),
            'sGroupImageUrl'    => App::getParam('groups.pic.url'),
            'sMonthDateFormat'  => App::getParam('format.monthdate%'),
            'info' => App::format('Mod_Groups.join_group', App::makeUrl('public.groups.join', array('id' => $aGroupData['id'])))
        ));
        $sHtml = $oTpl->fetch('GroupDetails.html');
        return $sHtml;
    }
}
?>